<template>
  <div class="box">
    <el-dialog title="关联角色" :visible.sync="closeBox" width="50%">
      <el-checkbox-group v-model="checkRole">
        <el-checkbox v-for="item in allRoleList" :key="item.id" :label="item.id">
          {{ item.name }}
        </el-checkbox>
      </el-checkbox-group>
      <span slot="footer">
        <el-button size="small" @click="closeBox = false">取消</el-button>
        <el-button size="small" type="primary" @click="btnOk">确定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { assignRole, getAssignRoleList } from '@/api/employee'
export default {
  name: 'AssignRole',
  data() {
    //
    return {
      closeBox: false,
      allRoleList: [], // 所有角色
      checkRole: [], //  选中角色
      userId: ''
    }
  },
  created() {
    this.getAllRole()
  },
  methods: {
    // 获取角色数据
    async getAllRole() {
      const res = await getAssignRoleList()
      this.allRoleList = res
    },
    // 提交
    async btnOk() {
      // 发送请求
      await assignRole({
        id: this.userId,
        roleIds: this.checkRole
      })
      this.$message.success('操作成功')
      this.closeBox = false
    }
  }
}
</script>

<style>

</style>
